package mil.af.amc.adpetracker.dao.hibernate;

import mil.af.amc.adpetracker.dao.TemplateFileDao;
import mil.af.amc.adpetracker.model.TemplateFile;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Please fill in this Javadoc
 *
 * @author TSgt Ferguson
 */
@Service("templateFileDao")
public class HibernateTemplateFileDao extends HibernateGenericDao<TemplateFile> implements TemplateFileDao {

    public HibernateTemplateFileDao() {
        super(TemplateFile.class);
    }

    public TemplateFile getByName(String name) {

        DetachedCriteria crit = DetachedCriteria.forClass(TemplateFile.class);
        crit.add(Restrictions.eq("name", name));

        List<TemplateFile> results =(List<TemplateFile>) getHibernateTemplate().findByCriteria(crit);

        if (results.size() < 1) {
            return null;
        }

        return results.get(0);

    }
}
